<?php

class BackendSiteController extends BackendController
{
    public function filters()
    {
        $parent_filters = parent::filters();
        // $parent_filters[] = 'filterFunction';
        return $parent_filters;
    }

    /**
     * Main page action
     * @return void
     */
    public function actionIndex()
    {
        $this->pageTitle = Yii::t('backendsite_index', 'PAGE_TITLE');
        $this->pageKeywords = '';
        $this->pageDescription = '';

        $this->render('index');
    }

    /**
     * Error action
     * @return void
     */
    public function actionError()
    {
        $this->pageTitle = Yii::t('backendsite_error', 'PAGE_TITLE');
        $this->pageKeywords = '';
        $this->pageDescription = '';

        if($error=Yii::app()->errorHandler->error)
        {
            if(Yii::app()->request->isAjaxRequest)
                echo $error['message'];
            else
                $this->render('error', $error);
        }
    }

    /**
     * Login form, validation and e-mail/password authentication controller
     * @return void
     */
    public function actionLogin()
    {
        $this->pageTitle = Yii::t('backendsite_login', 'PAGE_TITLE');
        $this->pageKeywords = '';
        $this->pageDescription = '';

        $login_form_model = new BackendLoginForm;
        if (Yii::app()->request->getPost('BackendLoginForm') !== null)
        {
            $login_form_model->attributes = Yii::app()->request->getPost('BackendLoginForm');
            if($login_form_model->validate() && $login_form_model->login())
                $this->redirect(Yii::app()->user->returnUrl, true, 301);
        }
        $this->render('login', array('login_form_model'=>$login_form_model));
    }

    /**
     * Logs out the current user and redirect to homepage.
     */
    public function actionLogout()
    {
        Yii::app()->user->logout();
        $this->redirect(Yii::app()->homeUrl);
    }

}
